// jquery cookie 辅助
jQuery.cookie = function(name, value, options) {   
    if (typeof value != 'undefined') { // name and value given, set cookie  
        options = options || {};  
        if (value === null) {  
            value = '';  
            options.expires = -1;  
        }  
        var expires = '';  
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {  
            var date;  
            if (typeof options.expires == 'number') {  
                date = new Date();  
                //date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));  
                date.setTime(date.getTime() + (options.expires * 60 * 1000));  
            } else {  
                date = options.expires;  
            }  
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE  
        }  
        // CAUTION: Needed to parenthesize options.path and options.domain  
        // in the following expressions, otherwise they evaluate to undefined  
        // in the packed version for some reason...  
        var path = options.path ? '; path=' + (options.path) : '';  
        var domain = options.domain ? '; domain=' + (options.domain) : '';  
        var secure = options.secure ? '; secure' : '';    
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');  
    } else { // only name given, get cookie  
        var cookieValue = null;  
        if (document.cookie && document.cookie != '') {  
            var cookies = document.cookie.split(';');  
            for (var i = 0; i < cookies.length; i++) {  
                var cookie = jQuery.trim(cookies[i]);  
                // Does this cookie string begin with the name we want?  
                if (cookie.substring(0, name.length + 1) == (name + '=')) {  
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));  
                    break;  
                }  
            }  
        }  
        return cookieValue;  
    }  
};
// GLOCAL SETTINGS
var TOPDRAW_EPG_BASE_SERVER = "http://qmkg.hnntv.cn/";
var TOPDRAW_EPG_SERVER = TOPDRAW_EPG_BASE_SERVER+"melody/SongContestWeb/";
var TOPDRAW_API_SERVER = TOPDRAW_EPG_BASE_SERVER+"hyperion.chimera/";
var IMAGE_BASE_PATH = TOPDRAW_EPG_BASE_SERVER+"hyperion.resource/";
var ENTRANCE_PATH = "http://qmkg.hnntv.cn/hyperion.chimera/index.jsp";
//各个平台投票对应分值映射
var g_oVotesScoreMap = {
    1 : 10,//IPTV
    2 : 5,//APP
    3 : 5,//WEB
    4 : 1//Wechat
}
var g_oVotesSignatureMap = {
    1 : "8778e97683f5ed9e",//IPTV
    2 : "256d9d839f7801fc",//APP
    3 : "0842e979b5d9c692",//WEB
    4 : "668d6400c143263f"//Wechat
}
var strCurrentAddr = window.location.href;
var arrPath = strCurrentAddr.split("?");
if(isWeiXin()){
    if(-1!=arrPath[0].indexOf("vote.html")){
        var strDirectURL = arrPath[0].replace(/vote\.html/,"votem.html");//+"?"+arrPath[1];
        if(-1!=arrPath[1].indexOf("token")&&-1!=arrPath[1].indexOf("ossUserId")){
            var arrParam = arrPath[1].split("&");
            for(var i = 0; i < arrParam.length; i++){
                var arrSeg = arrParam[i].split("=");
                $.cookie(arrSeg[0],arrSeg[1]);
            }
            strDirectURL = TOPDRAW_EPG_BASE_SERVER+'wechatlogin/Login?target='+encodeURIComponent(strDirectURL);
        }else{
            strDirectURL = ENTRANCE_PATH;
        }
        window.location.href = strDirectURL;
    }
    // 基础数据
    var g_strToken = $.cookie("token");
    var g_strUserId  = $.cookie("ossUserId");
    var CURRENT_VOTES_PLATFORM = 4;
}else{
    if(-1!=arrPath[0].indexOf("votem.html")){
        window.location.href = ENTRANCE_PATH;
    }
    // 基础数据
    var g_strToken = getQueryStringByName("token");
    var g_strUserId  = getQueryStringByName("ossUserId");
    var CURRENT_VOTES_PLATFORM = parseInt(getQueryStringByName("platform"))==2 ? 2 : 3;
}
var g_iRequestedMediaPageIndex=1;
var g_iCurrentMediaPageIndex=1;
var g_iMediaPageSize=4;
var g_oCategoryInfo = {};
var g_iUserLeftVotes = -1;
var search = "search";
var g_iSearchResultCount = 0;
var g_iSearchResultStep = 8;
var g_iSearchRequestCount = 0;
var g_strSearchValue = "";
var g_oMediaRequestStatus = {};
var g_iBefore = 0;
var g_iAfter = 0;
var g_oSongInfo = {};
var g_iGroupIndex = null;
var g_oVotesInfo = {};
$(document).ready(function(){
    if(isWeiXin()){
        initWXJDK();
    }
    g_iBefore = $(window).scrollTop();
    $(window).on('scroll',getMoreSearchResult);
    $.views.helpers({
        "renderMediaList": function(strTVLink,index){
            var strCategoryId = eval(strTVLink);
            g_oCategoryInfo[index] = strCategoryId;
            getMediaList(index);
        }
    });
    $.views.helpers({
        "getSingerName": function(strName){
            var arr = strName.split("-");
            return arr[arr.length-1];
        }
    });
    $.views.helpers({
        "getImage": function(val){
            var strSrc="img/media_bg.png";
            if (val && val!='' && val!='null') {
                if (val.list && val.list instanceof Array && val.list.length>0
                    &&val.map.normal && val.map.normal instanceof Array && val.map.normal.length>0
                ) {
                    if(val.list[val.map.normal[0]].fileUrl){
                        strSrc=IMAGE_BASE_PATH + val.list[val.map.normal[0]].fileUrl;
                    }
                }
            }
            return strSrc;
        }
    });
    $.views.helpers({
        "getVoteIndex": function(index){
            var iStart = 0;
            if(g_strSearchValue){
                iStart = (g_iSearchRequestCount-1)*g_iSearchResultStep;
            }
            return iStart + index;
        }
    });
    $(".search_box input").keyup(function(e){
        if(e.code == "Enter"){
            getMediaList();
        }
    });
    //获取剩余票数
    getUserLeftVotes();
    //获取参赛选手
    $.ajax({
        type:"get",
        contentType: "application/json;charset=UTF-8",
        url:TOPDRAW_API_SERVER+'Promotion/ListItemByName',
        data : {
            "view":"json",
            "start":"0",
            "limit":"100",
            "name":"VotingChannel",
            "sortField":"top",
            "sortDirection":"asc",
            "token":g_strToken
        },
        success:function(data){
            var oJSONResultset;
            oJSONResultset=data.resultSet;
            var html = $("#tmplNavigator").render(oJSONResultset);
            var elGroup =  $(".contestant_group_list_wrapper");
            elGroup.html(html);
        }
    });
    
    
});
function getUserLeftVotes(){
    $.ajax({
        type:"get",
        contentType: "application/json;charset=UTF-8",
        url:TOPDRAW_API_SERVER+'Contest/UserCapable',
        data : {
            'view':"json",
            'userId' : g_strUserId,
            'platform' : CURRENT_VOTES_PLATFORM
        },
        success:function(data){
            var oJSONResultset;
            oJSONResultset=data.resultSet;
            if(oJSONResultset.length){
                g_iUserLeftVotes = oJSONResultset[0].voteCapable;
            }
        }
    });
}	
function flipover(iDir,index){
    var arr = $(".pager:eq("+index+") span").html().split("/");
    var iCurrentPage = parseInt(arr[0]);
    var iTotalPage = parseInt(arr[1]);
    if(iCurrentPage + iDir >=1 && iCurrentPage + iDir <= iTotalPage){
        iCurrentPage += iDir;
        getMediaList(index,iCurrentPage);
    }
}
function convertCode(strId,index){
    if(!g_iGroupIndex){
        g_iGroupIndex = index;
    }
    return strId;
}
function getMediaList(index,iRequestPageIndex){
    if(isNaN(index)){
        index = search;
    }
    if(g_oMediaRequestStatus[index]){
        return;
    }
    
    var strSearchValue = $(".search_value").val();
    var oParam = {};
    iRequestPageIndex = iRequestPageIndex || 1;
    if(strSearchValue){
        if(g_strSearchValue != strSearchValue){
            g_iSearchRequestCount = 1;
            $(".search_result ul").html("");
        }else{
            if(g_iSearchResultCount <= $(".search_result ul li").length){
                return;
            } 
            g_iSearchRequestCount++;
        }
        var oParam = {
            'view':"json",
            'singerName' : strSearchValue,
            'start':(g_iSearchRequestCount-1)*g_iSearchResultStep,
            'limit':g_iSearchResultStep,
            'token':g_strToken
        };
    }else{
        g_strSearchValue = "";
        oParam = {
            'view':"json",
            'categoryId':g_oCategoryInfo[index],
            'start':(iRequestPageIndex-1)*g_iMediaPageSize,
            'limit':g_iMediaPageSize,
            'token':g_strToken
        };
    }
    g_oMediaRequestStatus[index] = 1;
    $.ajax({
        type:"get",
        contentType: "application/json;charset=UTF-8",
        url:TOPDRAW_API_SERVER + 'Media/List',
        data : oParam,
        success:function(data){
            var oJSONResultset,aIds = [],aCodes = [],oIdIndex = {},iTime = (new Date()).getTime();
            oJSONResultset=data.resultSet;
            var html = $("#tmplSong").render(oJSONResultset,{parentIndex:index});
            if(strSearchValue){
                g_strSearchValue = strSearchValue;
                g_iSearchResultCount = data.count;
                if(oJSONResultset.length){
                    $(".no_content").hide(); 
                    var strOldHtml = $(".search_result ul").html();
                    $(".search_result ul").html(strOldHtml + html);
                    $(".search_result").show();
                    g_oCategoryInfo["extra"+index] = iTime;
                }else{
                    $(".no_content").show(); 
                }
                $(".contestant_group_list_wrapper").hide();
            }else{
                $(".contestant_group:eq("+index+") ul").html(html);
                $(".contestant_group_list_wrapper").show();
                $(".search_result").hide();
                if(oJSONResultset.length){
                    $(".contestant_group_list:eq("+index+")").show();
                }else{
                    $(".contestant_group_list:eq("+index+")").hide();
                }
                $(".pager:eq("+index+") span").html(iRequestPageIndex+"/"+Math.ceil(data.count/g_iMediaPageSize));
                g_oCategoryInfo["extra"+index] = iTime;
            }
            for(var i = 0; i < oJSONResultset.length; i++){
                g_oSongInfo[oJSONResultset[i].id] = g_oCategoryInfo[index];
                aIds.push(oJSONResultset[i].id);
                aCodes.push(oJSONResultset[i].code);
                oIdIndex[oJSONResultset[i].id] = i;
                oIdIndex[oJSONResultset[i].code] = i;
            }
            if(aIds.length){
                getContentsArtistInfo(aIds,iTime,copyObject(oIdIndex),index);
                getContentsVotesInfo(aCodes,iTime,copyObject(oIdIndex),index);
            }
            g_oMediaRequestStatus[index] = 0;
        },
        error : function(){
            g_oMediaRequestStatus[index] = 0;
        }

    });
}
function vote(strCode,index,iPIndex){
    if(g_iUserLeftVotes == -1){
        return;
    }
    if(g_iUserLeftVotes == 0){
        showVoteMessage();
        return;
    }
    //这里对投票按钮做一个锁定，防止频繁请求
    var elVoteBtn;
    if(isNaN(iPIndex)){
        elVoteBtn = $(".search_result .vote_btn:eq("+index+")");
    }else{
        elVoteBtn = $(".contestant_group:eq("+iPIndex+") .vote_btn:eq("+index+")");
    }
    if(elVoteBtn.hasClass("invalid")){
        return;
    }
    elVoteBtn.addClass("invalid");
    //if(g_oSongInfo[strId]){
        window.setTimeout(function(){
            elVoteBtn.removeClass("invalid");
        },2000);
        let oParam = {
            'view':"json",
            'userId' : g_strUserId,
            'content' : strCode,
            'platform' : CURRENT_VOTES_PLATFORM,
            'count' : 1,
            'stage':g_iGroupIndex,
            'timestamp' : parseInt((new Date()).getTime()/1000)
        }
        oParam['signature'] = getSignature(oParam);
        $.ajax({
            type:"get",
            contentType: "application/json;charset=UTF-8",
            url:TOPDRAW_API_SERVER+'Contest/Vote',
            data : oParam,
            success:function(data){
                if(data.businessCode == "success"){
                    getUserLeftVotes();
                    if(isNaN(iPIndex)){
                        var elVotesNumber = $(".search_result .song_score:eq("+index+") span");
                        var elRanking = $(".search_result .singer_ranking:eq("+index+") span");
                        var elScorePrompt = $(".search_result .song_score:eq("+index+") .score_prompt");
                    }else{
                        var elVotesNumber = $(".contestant_group:eq("+iPIndex+") .song_score:eq("+index+") span");
                        var elRanking = $(".contestant_group:eq("+iPIndex+") .singer_ranking:eq("+index+") span");
                        var elScorePrompt = $(".contestant_group:eq("+iPIndex+") .song_score:eq("+index+") .score_prompt");
                    }
                    elScorePrompt.html("");
                    elScorePrompt.html('<img src="img/score'+g_oVotesScoreMap[CURRENT_VOTES_PLATFORM]+'.png" class="score_prompt_img"/>');
                    elVotesNumber.html(parseInt(elVotesNumber.html()) + g_oVotesScoreMap[CURRENT_VOTES_PLATFORM]);//目前是显示分数
                    var oVoteCookie = JSON.parse($.cookie("vote_history")) || {};
                    if(oVoteCookie[strCode]){
                        oVoteCookie[strCode]++;
                    }else{
                        oVoteCookie[strCode] = 1;
                        oVoteCookie[strCode+"_score"] = g_oVotesInfo[strCode];
                    }
                    $.cookie('vote_history', JSON.stringify(oVoteCookie),{expires:5}); 
                }
                
            }
        });
    // }else{

    // }
    
}
function getContentsVotesInfo(aIds,iMediaRequestTag,oIdIndex,index){
    $.ajax({
        type:"get",
        contentType: "application/json;charset=UTF-8",
        url:TOPDRAW_API_SERVER+'Contest/ListVote',
        data : {
            'view':"json",
            'contents' : aIds.toString(),
            'stage' : g_iGroupIndex,
            'start':0,
            'limit':aIds.length,
            'platform' : CURRENT_VOTES_PLATFORM
        },
        success:function(data){
            var oJSONResultset;
            oJSONResultset=data.resultSet;
            if(iMediaRequestTag != g_oCategoryInfo["extra"+index]){
                return;
            }
            if(data.businessCode == "success"){
                var oVoteCookie;
                oVoteCookie = JSON.parse($.cookie("vote_history")) || {};
                if(oJSONResultset.length){
                    for(var i = 0; i < oJSONResultset.length; i++){
                        var key = oJSONResultset[i].content;
                        var iIndex = oIdIndex[key];
                        if(!isNaN(iIndex)){
                            var iRanking = oJSONResultset[i].index;
                            var iTotalScore = oJSONResultset[i].total_score;
                            var iVotesTotal = 0;
                            var iPlusVote;
                            var aScores = oJSONResultset[i].platform_vote_count;
                            for(var j =0; j <  aScores.length; j++){
                                if(aScores[j].platform == CURRENT_VOTES_PLATFORM){
                                    iPlusVote = oVoteCookie[key] || 0;
                                }
                                if(g_oVotesScoreMap[aScores[j].platform]){
                                    iVotesTotal += aScores[j].vote_count*g_oVotesScoreMap[aScores[j].platform];
                                }
                            }
                            g_oVotesInfo[key] = iVotesTotal;
                            if(iPlusVote&&iVotesTotal==oVoteCookie[key+"_score"]){
                                iVotesTotal += iPlusVote*g_oVotesScoreMap[CURRENT_VOTES_PLATFORM];
                            }else{
                                oVoteCookie[key] = 0;
                                oVoteCookie[key+"_score"] = iVotesTotal;
                            }
                            if(iTotalScore!=iVotesTotal){
                                console.log("计算总分数和给定总分数不相同！！"+"缓存加分数："+iPlusVote);
                            }
                            if(isNaN(index)){
                                $(".search_result .song_score:eq("+((g_iSearchRequestCount-1)*g_iSearchResultStep+iIndex)+") span").html(iVotesTotal);
                                $(".search_result .singer_ranking:eq("+((g_iSearchRequestCount-1)*g_iSearchResultStep+iIndex)+") span").html(iRanking);
                            }else{
                                $(".contestant_group:eq("+index+") .song_score:eq("+iIndex+") span").html(iVotesTotal);
                                $(".contestant_group:eq("+index+") .singer_ranking:eq("+iIndex+") span").html(iRanking);
                            }
                            oIdIndex[key] = null;
                        }
                    }
                }
                $.cookie('vote_history', JSON.stringify(oVoteCookie),{expires:5});
                for(var key2 in oIdIndex){
                    if(oIdIndex[key2] == null){
                        continue;
                    }
                    var bMediaCode = /[a-z]+_[0-9a-z]+/.test(key2);
                    if(!bMediaCode){
                        continue;
                    }
                    var iPlusVote2 = oVoteCookie[key2] || 0;
                    var iVotesTotal2 = iPlusVote2*g_oVotesScoreMap[CURRENT_VOTES_PLATFORM];
                    if(isNaN(index)){
                        $(".search_result .song_score:eq("+((g_iSearchRequestCount-1)*g_iSearchResultStep+iIndex)+") span").html(iVotesTotal2);
                    }else{
                        $(".contestant_group:eq("+index+") .song_score:eq("+iIndex+") span").html(iVotesTotal2);
                    }
                    oIdIndex[key2] = null;
                }
                console.log("Business Success:Request Contents Votes Info");
            }else{
                console.log("Business Failure:Request Contents Votes Info");
            }
        }
    });

}
function getContentsArtistInfo(aIds,iMediaRequestTag,oIdIndex,index){
    $.ajax({
        type:"get",
        contentType: "application/json;charset=UTF-8",
        url:TOPDRAW_API_SERVER+'Artist/ListByMedia',
        //url:"data/"+g_oCategoryInfo[index] +".json",
        data : {
            'view':"json",
            'mediaIds' : aIds.toString(),
            'start' : 0,
            'limit' : aIds.length,
            "token":g_strToken
        },
        success:function(data){
            var oJSONResultset;
            oJSONResultset=data.resultSet;
            if(iMediaRequestTag != g_oCategoryInfo["extra"+index]){
                return;
            }
            if(data.businessCode == "success"){
                for(var i = 0; i < oJSONResultset.length; i++){
                    var iIndex = oIdIndex[oJSONResultset[i].media_id];
                    if(!isNaN(iIndex)){
                        if(isNaN(index)){
                            $(".search_result .song_no:eq("+((g_iSearchRequestCount-1)*g_iSearchResultStep+iIndex)+") span").html(oJSONResultset[i].name ? oJSONResultset[i].name.split("-")[0] : "?");
                        }else{
                            $(".contestant_group:eq("+index+") .song_no:eq("+iIndex+") span").html(oJSONResultset[i].name ? oJSONResultset[i].name.split("-")[0] : "?");
                        }
                    }
                }
                console.log("Business Success:Request Contents Votes Info");
            }else{
                console.log("Business Failure:Request Contents Votes Info"+data);
            }
        }
    });
}
function showVoteMessage(){
    $(".vote_message_wrapper").show();
    $(document).bind('mousewheel', function(event, delta) {return false;});
}
function hideVoteMessage(){
    $(".vote_message_wrapper").hide();
    $(document).unbind('mousewheel');
}
function getSignature(oParam){
    var aValidParams = ["stage","userId","content","platform","count","timestamp"];
    var strKey = g_oVotesSignatureMap[CURRENT_VOTES_PLATFORM];//
    var str2Sha = "";
    for(var i = 0 ; i < aValidParams.length; i++){
        str2Sha += oParam[aValidParams[i]]+",";
    }
    str2Sha += strKey;
    return hex_sha1(str2Sha);
}	
//获得QueryString数据
function getQueryStringByName(name) {
    var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
    if (result == null || result.length < 1) {
        return "";
    }
    return result[1];
}
function getMoreSearchResult(){
    g_iAfter = $(window).scrollTop();
    if (g_iBefore < g_iAfter) {
        //console.log('上');
        var iTolerantVal = $(".footer").height();
        if($(".footer").is(':hidden')){
            iTolerantVal = 0;
        }
        if($(window).height() + window.scrollY > $(document).height() - iTolerantVal -10){//10是个微小的距离
            console.log("到极限了");
            if(g_strSearchValue){
                getMediaList();
            }
            
        }
    };
    if (g_iBefore > g_iAfter) {
        //console.log('下');
    };
    g_iBefore = g_iAfter;
}
function isWeiXin() {
    //判断是否是微信浏览器的函数
    //window.navigator.userAgent属性包含了浏览器类型、版本、操作系统类型、浏览器引擎类型等信息，这个属性可以用来判断浏览器类型
    var ua = window.navigator.userAgent.toLowerCase();
    //通过正则表达式匹配ua中是否含有MicroMessenger字符串
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        return true;
    } else {
        return false;
    }
}
function initWXJDK(){
    var shareInfo = {
        link : ENTRANCE_PATH,
        title : '海南网络电视台k歌大赛',
        description : '祝福祖国70周年华诞，建设美丽海南',
        image : TOPDRAW_EPG_SERVER+'img/logo.png'
    };
    $.getJSON(TOPDRAW_EPG_BASE_SERVER+'wechatlogin/wx_config.html', { 'location': location.href }, function (json) {
    //$.getJSON('http://localhost:8080/wechatlogin/wx_config.html', { 'location': location.href }, function (json) {
        if (json.businessCode == "success") {
            g_strUserId = json.t.replace(/\slogin/g,"");
            json.data.jsApiList = $.parseJSON(json.data.jsApiList);
            wx.config(json.data);
            wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
                // 自定义“分享给朋友”及“分享到QQ”按钮的分享内容（1.4.0）
                wx.updateAppMessageShareData({
                    title: shareInfo.title, // 分享标题
                    desc: shareInfo.description, // 分享描述
                    link: shareInfo.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: shareInfo.image, // 分享图标
                    success: function () {
                        // 设置成功
                    }
                });
                // 自定义“分享到朋友圈”及“分享到QQ空间”按钮的分享内容（1.4.0）
                wx.updateTimelineShareData({
                    title: shareInfo.title, // 分享标题
                    link: shareInfo.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: shareInfo.image, // 分享图标
                    success: function () {
                        // 设置成功
                    }
                });

                try {

                    // 获取“分享到朋友圈”按钮点击状态及自定义分享内容接口（即将废弃）
                    wx.onMenuShareTimeline({
                        title: shareInfo.title, // 分享标题
                        link: shareInfo.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                        imgUrl: shareInfo.image, // 分享图标
                        success: function () {
                            // 用户点击了分享后执行的回调函数
                        }
                    });
                    // 获取“分享给朋友”按钮点击状态及自定义分享内容接口（即将废弃）
                    wx.onMenuShareAppMessage({
                        title: shareInfo.title, // 分享标题
                        desc: shareInfo.description, // 分享描述
                        link: shareInfo.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                        imgUrl: shareInfo.image, // 分享图标
                        type: '', // 分享类型,music、video或link，不填默认为link
                        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                        success: function () {
                            // 用户点击了分享后执行的回调函数
                        }
                    });
                    // 获取“分享到QQ”按钮点击状态及自定义分享内容接口（即将废弃）
                    wx.onMenuShareQQ({
                        title: shareInfo.title, // 分享标题
                        desc: shareInfo.description, // 分享描述
                        link: shareInfo.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                        imgUrl: shareInfo.image, // 分享图标
                        success: function () {
                            // 用户确认分享后执行的回调函数
                        },
                        cancel: function () {
                            // 用户取消分享后执行的回调函数
                        }
                    });

                    // 获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口
                    wx.onMenuShareWeibo({
                        title: shareInfo.title, // 分享标题
                        desc: shareInfo.description, // 分享描述
                        link: shareInfo.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                        imgUrl: shareInfo.image, // 分享图标
                        success: function () {
                            // 用户确认分享后执行的回调函数
                        },
                        cancel: function () {
                            // 用户取消分享后执行的回调函数
                        }
                    });
                    //  获取“分享到QQ空间”按钮点击状态及自定义分享内容接口（即将废弃）
                    wx.onMenuShareQZone({
                        title: shareInfo.title, // 分享标题
                        desc: shareInfo.description, // 分享描述
                        link: shareInfo.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                        imgUrl: shareInfo.image, // 分享图标
                        success: function () {
                            // 用户确认分享后执行的回调函数
                        },
                        cancel: function () {
                            // 用户取消分享后执行的回调函数
                        }
                    });
                } catch (e) {

                }
            });
        }
    });

}
function copyObject(obj){
    var o = {};
    for(var key in obj){
        o[key] = obj[key];
    }
    return o;
}